package com.etc;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author kalista
 * @Description
 * @Date 2020/10/28  15:32
 **/
public class Test {
    public static void main(String[] args) throws IOException {
        test("E:\\Java架构师\\3.Java高级开发工程师");
    }

    public static void test(String fileDir) throws IOException {
        List<File> fileList = new ArrayList<File>();
        File file = new File(fileDir);
        File[] files = file.listFiles();
        if (files == null) {// 如果目录为空，直接退出
            return;
        }
        for (File f : files) {
            if (f.isFile()) {
                fileList.add(f);
            } else if (f.isDirectory()) {

                test(f.getAbsolutePath());
            }
        }

        for (File file1 : files) {
            String str = file1.getName();
            if (str.contains("微信：q1963029669")) {
                System.out.println(file1.getAbsolutePath());
                String oldFilename = file1.getAbsolutePath().substring(0, (file1.getAbsolutePath().indexOf("微信") - 2));
                System.out.println(oldFilename);
                File file2 = new File(oldFilename + ".mp4");
                if (file2.exists()) {
                    break;
                }
                if (file1.renameTo(file2)) {
                    System.out.println("重名名");
                }
            } else {
                continue;
            }


        }
    }
}
